package com.woniuxy.utils;

import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @author: 杜昊男  <br/>
 * Date: 2022/3/7:12:07  <br/>
 * Description:用于设置对应媒体类型允许的格式
 */
@Component
public class FileUtil {
    // 允许的后缀扩展名
    public static String[] IMAGE_FILE_EXTD = new String[]{"png", "bmp", "jpg", "jpeg"};
    public static String[] VIDEO_FILE_EXTD = new String[]{"mp4"};
    public static String[] OTHER_FILE_EXTD = new String[]{"doc","docx","pptx","pdf","xlsx"};

    public static boolean isImageFileAllowed(String fileName) {
        for (String ext : IMAGE_FILE_EXTD) {
            if (ext.equals(fileName)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isVideoFileAllowed(String fileName) {
        for (String ext : VIDEO_FILE_EXTD) {
            if (ext.equals(fileName)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isOtherFileAllowed(String fileName) {
        for (String ext : OTHER_FILE_EXTD) {
            if (ext.equals(fileName)) {
                return true;
            }
        }
        return false;
    }


}
